package com.peanut.controller;

import com.alibaba.fastjson.JSONObject;
import com.peanut.VehicleManagementFeign;
import com.peanut.common.Result;
import com.peanut.domain.vo.TabUserVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/*卖车*/
@Controller
@RequestMapping("sellCarsController")
public class SellCarsController {
    private Logger logger = LoggerFactory.getLogger(SellCarsController.class);

    @Resource
    private VehicleManagementFeign vehicleManagementFeign;

    /*卖车*/
    @RequestMapping("sellCarsByPullPhone")
    @ResponseBody
    public Result sellCarsByPullPhone(String phone, Integer jurisdiction) throws InvocationTargetException, IllegalAccessException {

        try {

            Result result = vehicleManagementFeign.getTabUserbyUserPhone(phone);

            String tabUserVOString = JSONObject.toJSONString(result.getData());

            TabUserVO tabUserVO = JSONObject.parseObject(tabUserVOString, TabUserVO.class);

            tabUserVO.setJurisdiction(jurisdiction);

            vehicleManagementFeign.updateTabUserbyId(tabUserVO);

            return Result.OK();
        } catch (Exception e) {
            logger.error("查询失败", e);
            return Result.ERROR();
        }

    }

}
